﻿//========================================================= 
/**@file LogDelegateAppender.h
 * @brief 通过回调函数处理日志的扩展类
 * 
 * @date 2019-08-08   15:49:40
 * @author Zhyioo 
 * @version 1.0
 */ 
//--------------------------------------------------------- 
#ifndef _LIBZHOUYB_LOGDELEGATEAPPENDER_H_
#define _LIBZHOUYB_LOGDELEGATEAPPENDER_H_
//--------------------------------------------------------- 
#include "../ILogCat.h"

#include <functional>
//--------------------------------------------------------- 
namespace zhou_yb {
namespace extension {
namespace logcat {
//--------------------------------------------------------- 
/**
 * @brief 通过调用回调实现日志输出的类
 * @date 2019-08-08 15:50
 */
class LogDelegateAppender : public ILogAppender, public RefObject
{
public:
    typedef std::function<void(LogLevel, const char*, const char*)> LogDelegateType;
protected:
    LogDelegateType _handler;
public:
    LogDelegateType SetHandler(LogDelegateType handler)
    {
        LogDelegateType lastHandler = _handler;
        _handler = handler;
        return lastHandler;
    }
    virtual void append(LogLevel lv, const char* tag, const char* str)
    {
        if(_handler)
        {
            _handler(lv, tag, str);
        }
    }
};
//--------------------------------------------------------- 
} // namespace logcat
} // namespace extension
} // namespace zhou_yb
//--------------------------------------------------------- 
#endif // _LIBZHOUYB_LOGDELEGATEAPPENDER_H_
//========================================================= 